function data2fftLarSTHarmonic
format long;

Larx50=load('Larx50.out');
Larx100=load('Larx100.out');
Larx150=load('Larx150.out');
Larx200=load('Larx200.out');
Larx250=load('Larx250.out');
Larx300=load('Larx300.out');
Larx350=load('Larx350.out');
Larx400=load('Larx400.out');
Larx450=load('Larx450.out');
Larx500=load('Larx500.out');
Larx550=load('Larx550.out');

Larx50=[Larx50(:,1) Larx50(:,2)];
Larx100=[Larx100(:,1) Larx100(:,2)];
Larx150=[Larx150(:,1) Larx150(:,2)];
Larx200=[Larx200(:,1) Larx200(:,2)];
Larx250=[Larx250(:,1) Larx250(:,2)];
Larx300=[Larx300(:,1) Larx300(:,2)];
Larx350=[Larx350(:,1) Larx350(:,2)];
Larx400=[Larx400(:,1) Larx400(:,2)];
Larx450=[Larx450(:,1) Larx450(:,2)];
Larx500=[Larx500(:,1) Larx500(:,2)];
Larx550=[Larx550(:,1) Larx550(:,2)];

NNN=length(Larx50);

fftx50=fft(Larx50(:,2))/NNN;
fftx100=fft(Larx100(:,2))/NNN;
fftx150=fft(Larx150(:,2))/NNN;
fftx200=fft(Larx200(:,2))/NNN;
fftx250=fft(Larx250(:,2))/NNN;
fftx300=fft(Larx300(:,2))/NNN;
fftx350=fft(Larx350(:,2))/NNN;
fftx400=fft(Larx400(:,2))/NNN;
fftx450=fft(Larx450(:,2))/NNN;
fftx500=fft(Larx500(:,2))/NNN;
fftx550=fft(Larx550(:,2))/NNN;

% Write the initial conditions to a file.
% These initial conditions are needed by the Fortran solvers.

ZeroModeLoc=157;
deltak=1/(Larx50(NNN,1)-Larx50(1,1));
kvec=transpose(0:deltak:(NNN-1)*deltak);
k0=1.52759556257556977
epsilon=2*k0*abs(fftx50(ZeroModeLoc))

% Compute M norms and exponential fit.

x50Mnorm=0;
x100Mnorm=0;
x150Mnorm=0;
x200Mnorm=0;
x250Mnorm=0;
x300Mnorm=0;
x350Mnorm=0;
x400Mnorm=0;
x450Mnorm=0;
x500Mnorm=0;
x550Mnorm=0;

for j=118:196
    x50Mnorm=x50Mnorm+abs(fftx50(j))^2;
    x100Mnorm=x100Mnorm+abs(fftx100(j))^2;
    x150Mnorm=x150Mnorm+abs(fftx150(j))^2;
    x200Mnorm=x200Mnorm+abs(fftx200(j))^2;
    x250Mnorm=x250Mnorm+abs(fftx250(j))^2;
    x300Mnorm=x300Mnorm+abs(fftx300(j))^2;
    x350Mnorm=x350Mnorm+abs(fftx350(j))^2;
    x400Mnorm=x400Mnorm+abs(fftx400(j))^2;
    x450Mnorm=x450Mnorm+abs(fftx450(j))^2;
    x500Mnorm=x500Mnorm+abs(fftx500(j))^2;
    x550Mnorm=x550Mnorm+abs(fftx550(j))^2;
end
 
positions=epsilon^2*k0*[0,50,100,150,200,250,300,350,400,450,500]';
xdata=epsilon^2*k0*linspace(0,500,100)';
Mnorms=(k0/epsilon)^2*[x50Mnorm,x100Mnorm,x150Mnorm,x200Mnorm,x250Mnorm,x300Mnorm,x350Mnorm,x400Mnorm,x450Mnorm,x500Mnorm,x550Mnorm]';
logMnorms=log(Mnorms);
coeffs=polyfit(positions,logMnorms,1);
Mpred=exp(polyval(coeffs,xdata));
delta=-coeffs(1)/2
L2Scaling=exp(2*delta.*(positions));
ScaledMnorms=Mnorms.*L2Scaling;

figure(3)
subplot(2,1,1)
hold off
scatter(positions,Mnorms,'filled','k')
hold on
plot(xdata,Mpred,'r','LineWidth',2)
text(0.05,0.12,strcat('Computed \delta=',num2str(delta)),'FontSize',13,'FontName','Times')
ylabel('$\mathcal{M}$','Interpreter','Latex')
legend('data','best fit exp','Location','NorthEast')
title('$\mathcal{M}$','Interpreter','Latex')

subplot(2,1,2)
hold off
scatter(positions,ScaledMnorms,'filled','k')
hold on
plot([0 0.14],[(k0/epsilon)^2*x50Mnorm (k0/epsilon)^2*x50Mnorm],'r','LineWidth',2)
text(0.05,0.47,strcat('Using \delta=',num2str(delta)),'FontSize',13,'FontName','Times')
xlabel('$\chi$','Interpreter','Latex')
ylabel('$\mathcal{M}$','Interpreter','Latex')
leg1=legend('scaled data','$\mathcal{M}(0)$','Location','NorthEast');
set(leg1,'Interpreter','Latex');
title('Scaled $\mathcal{M}$','Interpreter','Latex')
